home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.09 Sep 96 / C++ DebugStr / testdebug.cp < prev   
Encoding:
Text File  |  1996-06-18  |  3.7 KB  |  164 lines  |  [TEXT/R*ch]

  1. // (c) copyright 1995,1996, Jon Kalb, Liberty Software
  2. // Kalb@LibertySoft.com
  3. // You may freely incorporate this code into any machine-
  4. // readable project. You may modify this code, but you may
  5. // not remove this statement. 
  6.  
  7. #define d(s) s
  8.  
  9.  
  10. #ifdef COMMENT
  11.  
  12.     In my testing, I found that with CodeWarrior, dout was
  13.     constructed in time for use by by static object, but not
  14.     with Think Project Manager. (This is not a fault of TPM,
  15.     because the language does not guarantee that it will
  16.     be.)
  17.  
  18.     I also found that the library provided with CodeWarrior
  19.     did not properly format the "+0x64" at the end of the
  20.     test, but TPM did. (With CodeWarrior it came out as
  21.     +100.)
  22.  
  23. #endif    // COMMENT
  24.  
  25. #include "doutstream"
  26.  
  27. #include "streamstructsmac.h"
  28.  
  29. #ifdef COMMENT
  30.  
  31.     The privateMembers example is included only to show how
  32.     to create overloads that access private (or protected)
  33.     members.
  34.  
  35. #endif    // COMMENT
  36.  
  37. class privateMembers
  38. {
  39.     // This example is included only to show how to create
  40.     // insertion operator overloads that access private (or
  41.     // protected) members.
  42.     public:
  43.             privateMembers() {fA = 3; fB = 2;};
  44.             ~privateMembers() {};
  45.     private:
  46.         int fA;
  47.         int fB;
  48.  
  49.     friend ostream &operator<<(ostream &stream,
  50.         const privateMembers &rhs);
  51. };
  52.  
  53. ostream &operator<<(ostream &stream,
  54.         const privateMembers &rhs);
  55.  
  56. ostream &operator<<(ostream &stream,
  57.     const privateMembers &rhs)
  58. {
  59.     stream << ".fA(" << rhs.fA << ") ";
  60.     stream << ".fB(" << rhs.fB << ") ";
  61.     return stream;
  62. }
  63.  
  64. #ifdef COMMENT
  65.  
  66.     The staticObject example is included only to illustrate
  67.     the use of dout in the constructor of a static object.
  68.  
  69. #endif    // COMMENT
  70.  
  71. class staticObject
  72. {
  73.     public:
  74.             staticObject();
  75.             ~staticObject();
  76. };
  77.  
  78. staticObject::staticObject()
  79. {
  80.     // this may cause us great problems depending on
  81.     // whether or not dout has been constructed
  82. //    dout << "staticObject::staticObject()\n";
  83. }
  84.  
  85. staticObject::~staticObject()
  86. {
  87.     dout << "staticObject::~staticObject()\n";
  88. }
  89.  
  90. static staticObject charlie;
  91.  
  92.  
  93. int main()
  94. {
  95.     dout << doutformfeed;
  96.  
  97.     dout << "streaming strings, chars, and ints\n";
  98.     dout << 'M' << 'a' << 'c' << ' ' << 1984 << endl;
  99.  
  100.     dout << doutformfeed;
  101.  
  102.     dout << "streaming special characters\n";
  103.     dout << "backspace > " << doutbackspace <<
  104.             "< is there a space?" << endl;
  105.     dout << "form feed" << doutformfeed << endl;
  106.     dout << "new " << '\n' << endl << '\n';
  107.     dout << "return " << '\r' << endl << '\r';
  108.     dout << "tab " << douttab << "is this tabbed?" << endl;
  109.     dout << "vert " << doutverttab << "is this tabbed?"
  110.             << endl;
  111.     dout << "alert " << doutsysbeep << endl;
  112.     dout << "null are we in the debugger? " << doutdropin
  113.             << endl;
  114.     dout << "EOT are we in the debugger? " << '\x3' << endl;
  115.  
  116.  
  117.     dout << doutformfeed;
  118.  
  119.     dout << "streaming a object with private members\n";
  120.     privateMembers    pmObject;
  121.     
  122.     dout << pmObject << endl;
  123.  
  124.     dout << doutformfeed;
  125.  
  126.     dout << "streaming a Macintosh structures\n";
  127.     Point p;
  128.     Rect r;
  129.     BitMap b;
  130.  
  131.     p.v = 1;    p.h = 2;
  132.     r.top = 3;    r.left = 4;    r.bottom = 5;    r.right = 6;
  133.     b.baseAddr = (Ptr)0x12345678;    b.rowBytes = 7;
  134.     b.bounds = r;
  135.  
  136.     dout << "point: " << p << endl;
  137.     dout << "rect: " << r << endl;
  138.     dout << "bitmap: " << endl;
  139.     dout << b << doutdebug;    // drops us in the debugger
  140.  
  141.     dout << doutformfeed;
  142.  
  143.     char test[] = "This is a test of MacsBug commands";
  144.     dout << doutcommand << "dm #" << (unsigned long)test
  145.             << doutsoftflush;
  146.  
  147.     dout << doutformfeed;
  148.     dout << "fun and games with standard streams\n";
  149.     showflags(dout);
  150.     dout.setf(ios::right | ios::showpoint | ios::fixed);
  151.     dout << showflags;
  152.     dout.setf(ios::showpos);
  153.     dout.setf(ios::hex);
  154.     dout.setf(ios::showbase);
  155.     dout << showflags;
  156.     dout << 100;
  157.     dout << " this should be +0x64. If it isn't the";
  158.     dout << " implementation of your standard library";
  159.     dout << " is suspect.\n";
  160.  
  161.     return 0;
  162. }
  163.  
  164.